package com.ruoyi.cs.service.impl;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.Response;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.cs.domain.TUser;
import com.ruoyi.cs.mapper.TUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cs.mapper.TUserFeedbackMapper;
import com.ruoyi.cs.domain.TUserFeedback;
import com.ruoyi.cs.service.ITUserFeedbackService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户反馈信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-05-25
 */
@Service
@SuppressWarnings("ALL")
public class TUserFeedbackServiceImpl implements ITUserFeedbackService 
{
    @Autowired
    private TUserFeedbackMapper tUserFeedbackMapper;
    @Autowired
    private TUserMapper tUserMapper;
    /**
     * 查询用户反馈信息
     * 
     * @param id 用户反馈信息ID
     * @return 用户反馈信息
     */
    @Override
    public TUserFeedback selectTUserFeedbackById(String id)
    {
        return tUserFeedbackMapper.selectTUserFeedbackById(id);
    }

    /**
     * 查询用户反馈信息列表
     * 
     * @param tUserFeedback 用户反馈信息
     * @return 用户反馈信息
     */
    @Override
    public List<TUserFeedback> selectTUserFeedbackList(TUserFeedback tUserFeedback)
    {
        return tUserFeedbackMapper.selectTUserFeedbackList(tUserFeedback);
    }

    /**
     * 新增用户反馈信息
     * 
     * @param tUserFeedback 用户反馈信息
     * @return 结果
     */
    @Override
    public Response insertTUserFeedback(TUserFeedback tUserFeedback)
    {
        Long cou = tUserFeedbackMapper.countFeebackByUserId(tUserFeedback.getUserId());
        if (cou > 0) {
            return  Response.fail(Constants.FAILCODE,"有未处理的申诉！");
        }
        tUserFeedback.setCreateTime(DateUtils.getNowDate());
        tUserFeedback.setRemake1("0");
        tUserFeedbackMapper.insertTUserFeedback(tUserFeedback);
        return Response.success();
    }

    /**
     * 修改用户反馈信息
     * 
     * @param tUserFeedback 用户反馈信息
     * @return 结果
     */
    @Override
    @Transactional
    public int updateTUserFeedback(TUserFeedback tUserFeedback)
    {
        if ("1".equals(tUserFeedback.getRemake1())) {
            /**审核通过清空用户steramID*/
            tUserMapper.updateSteamID(tUserFeedback.getUserId());
        }
        tUserFeedback.setUpdateTime(DateUtils.getNowDate());
        int row = tUserFeedbackMapper.updateTUserFeedback(tUserFeedback);
        return row;
    }

    /**
     * 批量删除用户反馈信息
     * 
     * @param ids 需要删除的用户反馈信息ID
     * @return 结果
     */
    @Override
    public int deleteTUserFeedbackByIds(String[] ids)
    {
        return tUserFeedbackMapper.deleteTUserFeedbackByIds(ids);
    }

    /**
     * 删除用户反馈信息信息
     * 
     * @param id 用户反馈信息ID
     * @return 结果
     */
    @Override
    public int deleteTUserFeedbackById(String id)
    {
        return tUserFeedbackMapper.deleteTUserFeedbackById(id);
    }

    @Override
    public Long registeredNumber(String userType) {
        return tUserMapper.registeredNumber(userType);
    }
}
